#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

class Solution
{
private:
  bool inArea(vector<vector<char>> &grid, int r, int c)
  {
    return 0 <= r && r < grid.size() && 0 <= c && c < grid[0].size();
  }

  void dfs(vector<vector<char>> &grid, int r, int c, vector<vector<bool>> &visited)
  {
    // base case
    if (!inArea(grid, r, c))
      return;
//if(grid[r][c]=='0') return; // 来这治理
#往往这个base case容易被忽略
    if (grid[r][c] == '0')
    {
      return;
    }
    if (visited[r][c] == true)
      return;

    //grid[r][c] = '0'; // 将当前格的值设为0，表示已经遍历过
    visited[r][c] = true;
    // 遍历上下左右四个网格, 在其为连接岛屿的情况下
    dfs(grid, r - 1, c, visited); // 不管grid[r-1][c]是‘0’ or ‘1’, 先进去，即先污染后治理
    dfs(grid, r + 1, c, visited);
    dfs(grid, r, c - 1, visited);
    dfs(grid, r, c + 1, visited);
  }

public:
  int numIslands(vector<vector<char>> &grid)
  {
    int nr = grid.size();
    if (!nr)
      return 0;
    int nc = grid[0].size();
    vector<vector<bool>> visited(nr, vector<bool>(grid[0].size()));

    int num_islands = 0;
    for (int r = 0; r < nr; r++)
    {
      for (int c = 0; c < nc; c++)
      {
        if (grid[r][c] == '1' && visited[r][c] == false)
        {
          //++num_islands; // 若出现元素值为1，则岛屿数量加一
          dfs(grid, r, c, visited); // 使用深度优先遍历将此岛屿所有元素变为0
          num_islands++;
        }
      }
    }
    return num_islands;
  }
};

int main()
{
  Solution solute;
  int m, n;
  cin >> m;
  getchar(); // ','逗号
  cin >> n;

  string str;
  vector<vector<char>> data;

  int t = m;
  while (t-- && cin >> str)
  {
    vector<char> tmp(str.size());
    for (int i = 0; i < str.size(); i++)
    {
      tmp[i] = str[i];
    }
    data.push_back(tmp);
  }

  cout << solute.numIslands(data) << endl;

  return 0;
}